package rs.pnv.model.insurance;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_HOME_INSURANCE")
@XmlAccessorType(XmlAccessType.FIELD)
public class HomeInsurance extends AbstractEntity {

	public enum HomeInsuranceType {
		FLOD,
		FIRE,
		THEFT
	}

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private Integer duration;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private Double area;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private Integer yearsOld;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private BigDecimal estimatedValue;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private HomeInsuranceType type;

	@NotBlank
	@OneToOne
	@JoinColumn(nullable = false)
	@XmlElement(nillable = false)
	private Home home;

	public HomeInsurance() {

	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public Double getArea() {
		return area;
	}

	public void setArea(Double area) {
		this.area = area;
	}

	public Integer getYearsOld() {
		return yearsOld;
	}

	public void setYearsOld(Integer yearsOld) {
		this.yearsOld = yearsOld;
	}

	public BigDecimal getEstimatedValue() {
		return estimatedValue;
	}

	public void setEstimatedValue(BigDecimal estimatedValue) {
		this.estimatedValue = estimatedValue;
	}

	public HomeInsuranceType getType() {
		return type;
	}

	public void setType(HomeInsuranceType type) {
		this.type = type;
	}

	public Home getHome() {
		return home;
	}

	public void setHome(Home home) {
		this.home = home;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(duration)
				.append(area)
				.append(yearsOld)
				.append(estimatedValue)
				.append(type)
				.append(home)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final HomeInsurance otherHomeInsurance = (HomeInsurance) obj;

		return new EqualsBuilder()
				.append(duration, otherHomeInsurance.getDuration())
				.append(area, otherHomeInsurance.getArea())
				.append(yearsOld, otherHomeInsurance.getYearsOld())
				.append(estimatedValue, otherHomeInsurance.getEstimatedValue())
				.append(type, otherHomeInsurance.getType())
				.append(home, otherHomeInsurance.getHome())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("duration", duration)
				.append("area", area)
				.append("yearsOld", yearsOld)
				.append("estimatedValue", estimatedValue)
				.append("type", type)
				.append("house", home)
				.append(super.toString())
				.toString();
	}

}
